package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.entity.payresult.PayBean;
import com.lzm.ydpt.module.mall.activity.PayOrderActivity;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.PayOrderContract;
import com.lzm.ydpt.mvp.modelimpl.PayOrderModelImpl;

/**
 * 类名称：PayOrderPresenterImpl
 * 类描述：代理实现
 */
public class PayOrderPresenterImpl extends BasePresenter implements PayOrderContract.Presenter {

    private PayOrderContract.View mView;
    private PayOrderContract.Model mModel;

    public PayOrderPresenterImpl(PayOrderActivity context) {
        super(context);
        this.mView = context;
        this.mModel = new PayOrderModelImpl();
    }

    @Override
    public void onPayOrder(FormBodys formBodys) {
        mManager.http(mModel.onPayOrder(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<PayBean>() {
            @Override
            public void onLoadingResult(BaseResponseBean<PayBean> entity) {
                mView.onPayOrder(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onPayOrder"));
    }
}